﻿using AdverseEventReportSystem.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using FluentData;
using AdverseEventReportSystem.Model;
using AdverseEventReportSystem.Service;
using AdverseEventReportSystem.BLL.ServiceReference1;
using AdverseEventReportSystem.Utils;
using System.Data;

namespace AdverseEventReportSystem.BLL
{
    public class AdverseEventManager : BaseManager
    {
        /// <summary>
        /// 添加/编辑
        /// </summary>
        /// <param name="adverseEventInfo"></param>
        /// <returns></returns>
        public static OperateResult Save(AdverseEventInfo adverseEventInfo)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                using (IDbContext context = Db.GetInstance().Context())
                {
                    context.UseTransaction(true);
                    resultInfo = Save(adverseEventInfo, context);
                    if (resultInfo.Result == 1)
                    {
                        context.Commit();
                    }
                    else
                    {
                        context.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 添加/编辑
        /// </summary>
        /// <param name="adverseEventInfo"></param>
        /// <returns></returns>
        public static OperateResult Save(AdverseEventInfo adverseEventInfo, IDbContext context)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                resultInfo = CheckStatus(adverseEventInfo.AdverseEvent.ID, adverseEventInfo.AdverseEvent.Status, adverseEventInfo.OldStatus, context);
                if (resultInfo.Result == 0)
                {
                    return resultInfo;
                }

                AdverseEvent adverseEvent = adverseEventInfo.AdverseEvent;
                int eventID = adverseEventInfo.AdverseEvent.ID;
                int typeID = adverseEventInfo.AdverseEvent.EventTypeID;
                DateTime now = DateTime.Now;
                if (adverseEventInfo.NurseList != null)
                {
                    adverseEvent.NurseID = string.Join(",", adverseEventInfo.NurseList.Select(row => row.NurseID));
                    adverseEvent.NurseName = string.Join(",", adverseEventInfo.NurseList.Select(row => row.NurseName));
                }

                SysLoginUser loginUser = LoginManager.GetLoginUser();
                if (adverseEvent.DataSource == 1)
                {
                    loginUser = new SysLoginUser();
                    loginUser.CurrDepCode = adverseEvent.OccurrDepartID;
                    loginUser.CurrDepName = adverseEvent.OccurrDepartName;
                    loginUser.Personnel_id = adverseEvent.CreateUserID;
                }

                if (eventID == 0)
                {
                    #region 添加不良事件

                    adverseEvent.AreaID = loginUser.CurrDepCode;
                    adverseEvent.AreaName = loginUser.CurrDepName;
                    adverseEvent.CreateUserID = loginUser.Personnel_id;
                    adverseEvent.CreateTime = now;
                    if (adverseEvent.Flag_Yc == "1") adverseEvent.OccurrTime = now;
                    if (adverseEvent.Status == 1) adverseEvent.ReportTime = now;
                    eventID = AdverseEventService.Add(adverseEvent, context);
                    if (eventID == 0)
                    {
                        resultInfo.Result = 0;
                    }

                    #endregion
                }
                else
                {
                    #region 编辑不良事件

                    AdverseEvent oldAdverseEvent = AdverseEventService.GetQuerySingleByID(eventID, context);
                    if (adverseEvent.IsOutpatient == 1)
                    {
                        adverseEvent.PatientInTime = null;
                        adverseEvent.PatientID = null;
                        adverseEvent.PatientBedNo = null;
                        adverseEvent.PatientNursingGrade = null;
                        adverseEvent.IsTransfer = 0;
                        adverseEvent.TransferTime = null;
                        adverseEvent.TransferDepartCode = null;
                        adverseEvent.TransferDepartName = null;
                    }
                    oldAdverseEvent.EventTypeID = adverseEvent.EventTypeID;
                    oldAdverseEvent.EventTypeName = adverseEvent.EventTypeName;
                    oldAdverseEvent.OccurrDepartID = adverseEvent.OccurrDepartID;
                    oldAdverseEvent.OccurrDepartName = adverseEvent.OccurrDepartName;
                    oldAdverseEvent.PatientID = adverseEvent.PatientID;
                    oldAdverseEvent.PatientName = adverseEvent.PatientName;
                    oldAdverseEvent.PatientSex = adverseEvent.PatientSex;
                    oldAdverseEvent.PatientAge = adverseEvent.PatientAge;
                    oldAdverseEvent.PatientAgeMonth = adverseEvent.PatientAgeMonth;
                    oldAdverseEvent.PatientAgeWeek = adverseEvent.PatientAgeWeek;
                    oldAdverseEvent.PatientAgeDay = adverseEvent.PatientAgeDay;
                    oldAdverseEvent.PatientAgeStr = adverseEvent.PatientAgeStr;
                    oldAdverseEvent.PatientNursingGrade = adverseEvent.PatientNursingGrade;
                    oldAdverseEvent.PatientIsEscort = adverseEvent.PatientIsEscort;
                    oldAdverseEvent.PatientEscortValue = adverseEvent.PatientEscortValue;
                    oldAdverseEvent.PatientDiagnosis = adverseEvent.PatientDiagnosis;
                    oldAdverseEvent.PatientInTime = adverseEvent.PatientInTime;
                    oldAdverseEvent.PatientBedNo = adverseEvent.PatientBedNo;
                    oldAdverseEvent.PatientVisitID = adverseEvent.PatientVisitID;
                    oldAdverseEvent.IsTransfer = adverseEvent.IsTransfer;
                    oldAdverseEvent.TransferTime = adverseEvent.TransferTime;
                    oldAdverseEvent.TransferDepartCode = adverseEvent.TransferDepartCode;
                    oldAdverseEvent.TransferDepartName = adverseEvent.TransferDepartName;
                    if (adverseEvent.Flag_Yc != "1") oldAdverseEvent.OccurrTime = adverseEvent.OccurrTime;
                    oldAdverseEvent.NurseID = adverseEvent.NurseID;
                    oldAdverseEvent.NurseName = adverseEvent.NurseName;
                    oldAdverseEvent.NurseWorkTimes = adverseEvent.NurseWorkTimes;
                    oldAdverseEvent.EventGrade = adverseEvent.EventGrade;
                    oldAdverseEvent.EventGradeSubLevel = adverseEvent.EventGradeSubLevel;
                    oldAdverseEvent.EventCourse = adverseEvent.EventCourse;
                    oldAdverseEvent.Measures = adverseEvent.Measures;
                    oldAdverseEvent.Evaluation = adverseEvent.Evaluation;
                    oldAdverseEvent.SkinCondition = adverseEvent.SkinCondition;
                    oldAdverseEvent.ExceptionalCase = adverseEvent.ExceptionalCase;
                    oldAdverseEvent.Status = adverseEvent.Status;
                    oldAdverseEvent.YuHou = adverseEvent.YuHou;
                    oldAdverseEvent.ZhuanGui = adverseEvent.ZhuanGui;
                    oldAdverseEvent.IsOutpatient = adverseEvent.IsOutpatient;
                    oldAdverseEvent.OutpatientTime = adverseEvent.OutpatientTime;
                    oldAdverseEvent.OutpatientId = adverseEvent.OutpatientId;


                    if (oldAdverseEvent.Status == 1) oldAdverseEvent.ReportTime = now;
                    oldAdverseEvent.UpdateUserID = loginUser.Personnel_id;
                    oldAdverseEvent.UpdateTime = now;

                    int rows = AdverseEventService.Update(oldAdverseEvent, context);
                    if (rows == 0)
                    {
                        resultInfo.Result = 0;
                    }
                    else
                    {
                        AdverseEventModeRecordService.DelByEventID(eventID, context);
                        AdverseEventYaChuangFsbwService.DelByEventID(eventID, context);
                        AdverseEventReasonRecordService.DelByEventID(eventID, context);
                        AdverseEventNurseService.DelByEventID(eventID, context);
                        AdverseEventYcFanKuiService.DelByEventID(eventID, context);
                    }

                    #endregion
                }
                if (resultInfo.Result == 1)
                {
                    #region 添加发生方式

                    List<AdverseEventModeRecord> modeList = adverseEventInfo.ModeList;
                    if (modeList != null)
                    {
                        foreach (var item in modeList)
                        {
                            item.EventID = eventID;
                            item.TypeID = typeID;
                            item.CreateUserID = loginUser.Personnel_id;
                            item.CreateTime = now;
                            int id = AdverseEventModeRecordService.Add(item, context);
                            if (id == 0)
                            {
                                resultInfo.Result = 0;
                                break;
                            }
                        }

                    }
                    #endregion
                }
                if (resultInfo.Result == 1)
                {
                    #region 添加压疮发生部位

                    List<AdverseEventYaChuangFsbw> fsbwList = adverseEventInfo.YaChuangFsbwList;
                    if (fsbwList != null)
                    {
                        foreach (var item in fsbwList)
                        {
                            item.EventID = eventID;
                            item.CreateUserID = loginUser.Personnel_id;
                            item.CreateTime = now;
                            int id = AdverseEventYaChuangFsbwService.Add(item, context);
                            if (id == 0)
                            {
                                resultInfo.Result = 0;
                                break;
                            }
                        }
                    }

                    #endregion
                }
                if (resultInfo.Result == 1)
                {
                    #region 添加根因

                    List<AdverseEventReasonRecord> reasonRecordList = adverseEventInfo.ReasonList;
                    if (reasonRecordList != null)
                    {
                        for (int i = 0; i < reasonRecordList.Count; i++)
                        {
                            AdverseEventReason adverseEventReason = AdverseEventReasonService.GetQuerySingleByID(reasonRecordList[i].ID);
                            AdverseEventReasonRecord reasonRecord = new AdverseEventReasonRecord();
                            reasonRecord.EventID = eventID;
                            reasonRecord.TypeID = adverseEventReason.TypeID;
                            reasonRecord.ReasonID = adverseEventReason.ID;
                            reasonRecord.Reason = adverseEventReason.Reason;
                            reasonRecord.OtherReason = reasonRecordList[i].OtherReason;
                            reasonRecord.ParentID = adverseEventReason.ParentID;
                            reasonRecord.CreateUserID = loginUser.Personnel_id;
                            reasonRecord.CreateTime = now;

                            int id = AdverseEventReasonRecordService.Add(reasonRecord, context);
                            if (id == 0)
                            {
                                resultInfo.Result = 0;
                                break;
                            }
                        }
                    }

                    #endregion
                }
                if (resultInfo.Result == 1)
                {
                    #region 添加当事人

                    List<AdverseEventNurse> nurseList = adverseEventInfo.NurseList;
                    if (nurseList != null)
                    {
                        foreach (var item in nurseList)
                        {
                            item.EventId = eventID;
                            item.CreateUserID = loginUser.Personnel_id;
                            item.CreateTime = now;
                            int id = AdverseEventNurseService.Add(item, context);
                            if (id == 0)
                            {
                                resultInfo.Result = 0;
                                break;
                            }
                        }
                    }

                    #endregion
                }
                if (resultInfo.Result == 1)
                {
                    #region 添加压疮反馈信息

                    AdverseEventYcFanKui ycFanKui = adverseEventInfo.YcFanKui;
                    if (ycFanKui != null)
                    {
                        ycFanKui.EventId = eventID;
                        ycFanKui.CreateUserID = loginUser.Personnel_id;
                        ycFanKui.CreateTime = now;
                        int id = AdverseEventYcFanKuiService.Add(ycFanKui, context);
                        if (id == 0)
                        {
                            resultInfo.Result = 0;
                        }
                    }

                    #endregion
                }

                if (resultInfo.Result == 1)
                {
                    resultInfo.Body = eventID;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 校验状态是否正确
        /// </summary>
        /// <param name="id"></param>
        /// <param name="newStatus"></param>
        /// <param name="oldStatus"></param>
        /// <returns></returns>
        private static OperateResult CheckStatus(int id, int newStatus, int oldStatus, IDbContext context = null)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {

                if (id > 0)
                {
                    AdverseEvent adverseEvent = AdverseEventService.GetQuerySingleByID(id, context);
                    if (adverseEvent.Status != oldStatus)
                    {
                        resultInfo.Result = 0;
                        resultInfo.Body = "事件状态已改变";
                    }
                }

                if (resultInfo.Result == 1)
                {
                    if (id == 0)
                    {
                        if (newStatus != 0 && newStatus != 1)
                        {
                            resultInfo.Result = 0;
                            resultInfo.Body = "事件状态不正确";
                        }
                    }
                    else
                    {
                        bool flag = CheckReviewProcess("AdverseEvent\\ReviewProcess.xml", newStatus, oldStatus);
                        if (!flag)
                        {
                            if ((oldStatus == 0 || oldStatus == 3) && newStatus != 1 && newStatus != oldStatus)
                            {
                                resultInfo.Result = 0;
                                resultInfo.Body = "事件状态不正确";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;

        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static OperateResult Delte(int id)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                using (IDbContext context = Db.GetInstance().Context())
                {
                    context.UseTransaction(true);
                    AdverseEvent adverseEvent = AdverseEventService.GetQuerySingleByID(id, context);
                    if (adverseEvent.Status != 0 && adverseEvent.Status != 4)
                    {
                        resultInfo.Result = 0;
                    }
                    if (resultInfo.Result == 1)
                    {
                        AdverseEventService.DelByID(id, context);
                        AdverseEventModeRecordService.DelByEventID(id, context);
                        AdverseEventReasonRecordService.DelByEventID(id, context);
                        AdverseEventNurseService.DelByEventID(id, context);
                    }

                    if (resultInfo.Result == 1)
                    {
                        context.Commit();
                    }
                    else
                    {
                        context.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <param name="oldStatus"></param>
        /// <param name="duDaoRemark"></param>
        /// <param name="reviewReason"></param>
        /// <param name="yuHou"></param>
        /// <param name="zhuanGui"></param>
        /// <param name="adverseEventInfo"></param>
        /// <returns></returns>
        public static OperateResult Review(int id, int status, int oldStatus, string duDaoRemark, string reviewReason, string yuHou, string zhuanGui, AdverseEventInfo adverseEventInfo)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                using (IDbContext context = Db.GetInstance().Context())
                {
                    context.UseTransaction(true);
                    resultInfo = CheckStatus(id, status, oldStatus);

                    if (resultInfo.Result == 1)
                    {
                        Loginuser loginUser = LoginManager.GetLoginUser();
                        AdverseEvent adverseEvent = AdverseEventService.GetQuerySingleByID(id, context);
                        if (yuHou != (adverseEvent.YuHou == null ? "" : adverseEvent.YuHou) || zhuanGui != (adverseEvent.ZhuanGui == null ? "" : adverseEvent.ZhuanGui))
                        {
                            resultInfo.Result = 0;
                            resultInfo.Body = "反馈信息已更改，请刷新界面重新审核";
                        }

                        if (resultInfo.Result == 1)
                        {
                            if (adverseEventInfo != null)
                            {
                                if (adverseEvent.Flag_Yc == "1")
                                {
                                    adverseEventInfo.AdverseEvent.Flag_Yc = "1";
                                    adverseEventInfo.NurseList = new List<AdverseEventNurse>() { new AdverseEventNurse() { NurseID = adverseEvent.NurseID, NurseName = adverseEvent.NurseName } };
                                }
                                resultInfo = Save(adverseEventInfo, context);
                                if (resultInfo.Result == 1)
                                {
                                    adverseEvent = AdverseEventService.GetQuerySingleByID(id, context);
                                }
                            }
                        }

                        if (resultInfo.Result == 1)
                        {
                            adverseEvent.Status = status;
                            adverseEvent.DuDaoRemark = duDaoRemark;
                            adverseEvent.ReviewReason = reviewReason;
                            adverseEvent.ReviewTime = DateTime.Now;
                            adverseEvent.ReviewUserID = loginUser.Personnel_id;
                            if (status == 2)
                            {
                                adverseEvent.HeadNurseID = loginUser.Personnel_id;
                                adverseEvent.HeadNurseName = loginUser.Name;
                            }

                            int rows = AdverseEventService.Update(adverseEvent, context);
                            if (rows == 0)
                            {
                                resultInfo.Result = 0;
                            }
                        }
                    }

                    if (resultInfo.Result == 1)
                    {
                        context.Commit();
                    }
                    else
                    {
                        context.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 添加/编辑压疮(压伤)反馈
        /// </summary>
        /// <param name="ycFanKui"></param>
        /// <param name="oldStatus"></param>
        /// <returns></returns>
        public static OperateResult YcFanKuiSave(AdverseEventYcFanKui ycFanKui, int oldStatus)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                using (IDbContext context = Db.GetInstance().Context())
                {
                    context.UseTransaction(true);

                    AdverseEvent adverseEvent = AdverseEventService.GetQuerySingleByID(ycFanKui.EventId, context);
                    if (adverseEvent.Status != oldStatus)
                    {
                        resultInfo.Result = 0;
                        resultInfo.Body = "事件状态已改变，请刷新界面重新编辑";
                    }
                    else
                    {
                        if (adverseEvent.Status == 2)
                        {
                            adverseEvent.Status = 1;
                        }
                        if (adverseEvent.Status == 4)
                        {
                            adverseEvent.Status = 2;
                        }
                        if (adverseEvent.Status != oldStatus)
                        {
                            int rows = AdverseEventService.Update(adverseEvent, context);
                            if (rows == 0)
                            {
                                resultInfo.Result = 0;
                            }
                        }
                    }

                    var zhuanGui = "";
                    var yuHou = "";

                    if (resultInfo.Result == 1)
                    {
                        switch (ycFanKui.ZgType)
                        {
                            case 0:
                                zhuanGui += "出院 " + ycFanKui.ZgDate;
                                break;
                            case 1:
                                zhuanGui += "转科 " + ycFanKui.ZgDepartmentName + " " + ycFanKui.ZgDate;
                                break;
                        }

                        switch (ycFanKui.YhType)
                        {
                            case 0:
                                yuHou += "愈合";
                                break;
                            case 1:
                                yuHou += "好转 " + ycFanKui.YhRemarks;
                                break;
                            case 2:
                                yuHou += "加重 " + ycFanKui.YhRemarks;
                                break;
                            case 3:
                                yuHou += "无变化";
                                break;
                        }

                        adverseEvent.YuHou = yuHou;
                        adverseEvent.ZhuanGui = zhuanGui;
                        int rows = AdverseEventService.Update(adverseEvent, context);
                        if (rows == 0)
                        {
                            resultInfo.Result = 0;
                        }
                    }
                    if (resultInfo.Result == 1)
                    {
                        AdverseEventYcFanKuiService.DelByEventID(ycFanKui.EventId, context);
                        ycFanKui.CreateTime = DateTime.Now;
                        ycFanKui.CreateUserID = LoginManager.GetLoginUser().Name;
                        int id = AdverseEventYcFanKuiService.Add(ycFanKui, context);
                        if (id == 0)
                        {
                            resultInfo.Result = 0;
                        }
                    }
                    if (resultInfo.Result == 1)
                    {
                        resultInfo.Body = new { YuHou = yuHou, ZhuanGui = zhuanGui, Status = adverseEvent.Status };
                        context.Commit();
                    }
                    else
                    {
                        context.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 获取压伤类型
        /// </summary>
        /// <param name="dt"></param>
        public static void GetYsType(DataTable dt)
        {
            try
            {
                dt.Columns["YsType"].ReadOnly = false;
                DataTable depDt = null;
                OperateResult resultInfo = DepartmentManager.GetAllUnits();
                if (resultInfo.Result == 1)
                {
                    depDt = resultInfo.Body as DataTable;
                }
                foreach (DataRow item in dt.Rows)
                {
                    string ysType = item["YsType"].ToString();
                    if (string.IsNullOrEmpty(ysType))
                    {
                        item["YsType"] = "";
                        continue;
                    }
                    string[] options = ysType.Split('#');
                    for (int i = 0; i < options.Length; i++)
                    {
                        if (i == 0)
                        {
                            string value = options[i].Split('$')[0];
                            if (value == "1")
                            {
                                item["YsType"] = "（院外）";
                                break;
                            }
                        }
                        if (i == 2)
                        {
                            string value = options[i].Split('$')[0];
                            if (value == "1")
                            {
                                string departmentCode = options[i].Split('*')[1];
                                if (departmentCode != "-1")
                                {
                                    var departmentName = (from r in depDt.AsEnumerable()
                                                          where r.Field<string>("DepartmentCode") == departmentCode
                                                          select r.Field<string>("DepartmentName")).First();
                                    item["YsType"] = "（" + departmentName + "）";
                                }
                                break;
                            }
                        }
                    }
                    if (item["YsType"].ToString() == ysType)
                    {
                        item["YsType"] = "";
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// 获取不良事件数据（用于桌面页）
        /// </summary>
        /// <param name="dateType"></param>
        /// <returns></returns>
        public static OperateResult GetDeskAdverseEventData(string dateType)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                int addCount = 0;
                int reviewCount = 0;
                string status = GetDeskReviewStatus();
                DateTime now = DateTime.Now;
                Loginuser loginUser = LoginManager.GetLoginUser();

                SelectBuilder data = new SelectBuilder();
                data.From = "AdverseEvent";
                data.Select = "Sum(case when Status > 0 then 1 else 0 end ) AddCount,Count(1),Sum(case when Status = " + status + " then 1 else 0 end) ReviewCount";
                switch (dateType)
                {
                    case "month":
                        data.WhereSql = string.Format("CreateTime >= '{0}' and CreateTime < '{1}'", WebUtils.FirstDayOfMonth(now), WebUtils.LastDayOfMonth(now));
                        break;
                    case "year":
                        data.WhereSql = string.Format("CreateTime >= '{0}' and CreateTime < '{1}'", WebUtils.FirstDayOfYear(now), WebUtils.LastDayOfYear(now));
                        break;
                }

                data.WhereSql += "and AreaID in ('" + string.Join("','", loginUser.DepartCode.Split('&')) + "')";

                DataTable dt = BaseService<DataTable>.GetDataTableSelectBuilder(data);
                if (dt.Rows.Count == 1)
                {
                    addCount = DataConvert.StrToInt(dt.Rows[0]["AddCount"]);
                    reviewCount = DataConvert.StrToInt(dt.Rows[0]["ReviewCount"]);
                }

                resultInfo.Body = new { AddCount = addCount, ReviewCount = reviewCount, Status = status };
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 获取查询条件的审核状态（用于桌面页）
        /// </summary>
        private static string GetDeskReviewStatus()
        {
            string status = "-1";
            Job job = BaseManager.GetReviewProcess("AdverseEvent\\ReviewProcess.xml");
            if (!string.IsNullOrEmpty(job.IncludeStatus))
            {
                foreach (var item in job.IncludeStatus.Split('|'))
                {
                    if (item == "1")
                    {
                        status = "1";
                        break;
                    }
                    if (item == "2")
                    {
                        status = "2";
                        break;
                    }
                }
            }
            return status;
        }
    }
}
